Crate bevy_text

Source
Expand description

This crate provides the tools for positioning and rendering text in Bevy.

§Font

Fonts contain information for drawing glyphs, which are shapes that typically represent a single character, but in some cases part of a “character” (grapheme clusters) or more than one character (ligatures).

A font face is part of a font family, and is distinguished by its style (e.g. italic), its weight (e.g. bold) and its stretch (e.g. condensed).

In Bevy, Fonts are loaded by the FontLoader as assets.

§TextPipeline

The TextPipeline resource does all of the heavy lifting for rendering text.

UI Text is first measured by creating a TextMeasureInfo in TextPipeline::create_text_measure, which is called by the measure_text_system system of bevy_ui.

Note that text measurement is only relevant in a UI context.

With the actual text bounds defined, the bevy_ui::widget::text::text_system system (in a UI context) or text2d::update_text2d_layout system (in a 2d world space context) passes it into TextPipeline::queue_text, which:

  1. updates a Buffer from the TextSpans, generating new FontAtlasSets if necessary.
  2. iterates over each glyph in the Buffer to create a PositionedGlyph, retrieving glyphs from the cache, or rasterizing to a FontAtlas if necessary.
  3. PositionedGlyphs are stored in a TextLayoutInfo, which contains all the information that downstream systems need for rendering.

Re-exports§

Modules§

Structs§

Enums§

  • An owned version of Family
  • Possible errors that can be produced by FontLoader
  • Determines which antialiasing method to use when rendering text. By default, text is rendered with grayscale antialiasing, but this can be changed to achieve a pixelated look.
  • A face width.
  • Allows italic or oblique faces to be selected.
  • Describes the horizontal alignment of multiple lines of text relative to each other.
  • Determines how lines will be broken when preventing text from running out of bounds.
  • Errors related to the textsystem
  • Text is rendered for two different view projections; 2-dimensional text (Text2d) is rendered in “world space” with a BottomToTop Y-axis, while UI is rendered with a TopToBottom Y-axis. This matters for text because the glyph positioning is different in either layout. For TopToBottom, 0 is the top of the text, while for BottomToTop 0 is the bottom.

Constants§

Traits§

Functions§

Type Aliases§